package com.itheima.sh.test;

import com.itheima.sh.dao.OrderMapper;
import com.itheima.sh.pojo.Order;
import com.itheima.sh.util.SessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.BeforeClass;
import org.junit.Test;

public class MybatisOrderTest02 {
    private static SqlSession session = null;
    private static OrderMapper mapper = null;

    @BeforeClass
    public static void beaforClass() {
        //1.获取会话对象
        session = SessionFactoryUtils.getSession();
        //2.获取接口代理对象
        mapper = session.getMapper(OrderMapper.class);
    }

    /*
         1.定义方法实现一对一查询：需求：通过订单编号20140921003查询出订单信息，并查询出下单人信息。
         Order queryOneToOne(@Param("orderNumber") String orderNumber);
     */
    @Test
    public void queryOneToOne() {
        Order order = mapper.queryOneToOne("20140921003");
        System.out.println("order = " + order);
        //释放资源
        session.close();
    }

    /*
        【需求】：查询订单号为20140921001的订单的详情信息即查询订单信息+订单中的商品信息；
        Order queryManyToMany(@Param("orderNumber") String orderNumber);
    */
    @Test
    public void queryManyToMany() {
        Order order = mapper.queryManyToMany("20140921001");
        System.out.println("order = " + order);
        //释放资源
        session.close();
    }

    /*
       【需求】：根据订单号（20140921001） 查询订单信息  查询订单所属用户信息 查询订单中的详细商品信息
        Order queryManyToMany2(@Param("orderNumber") String orderNumber);
     */
    @Test
    public void queryManyToMany2() {
        Order order = mapper.queryManyToMany2("20140921001");
        System.out.println("order = " + order);
        //释放资源
        session.close();
    }
}
